package com.example.yyy

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_sentence.*
import org.jetbrains.anko.startActivity

class SentenceActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_sentence)
        //条件分支
        var boolean : Boolean = true;
        //简单分支
//        if(boolean){
//            st_tv_hello.text = "123"
//        }else{
//            st_tv_hello.text = "456"
//        }

//        st_tv_hello.text = if(boolean){
//            "123"
//        }else{
//            "456"
//        }

        st_tv_hello.text = if(boolean) "123"; else "456";
        var t = true
        st_tv_hello.setOnClickListener {
            if (t){
                val bundle = intent.extras
                val toTime = bundle?.getString("toTime") ?: ""
                val toInt =  bundle?.getInt("toInt") ?: 0
                st_tv_hello.text = toTime+toInt
                t=!t
            }else{
                t=!t
                startActivity<FunctionActivity>()
            }
        }
        var count : Int = 0;
//        when (count){
//            0 -> st_tv_hello.text = "123";
//            1 ->  st_tv_hello.text = "456";
//            else ->  st_tv_hello.text = "789"
//        }

        //可变量
        var odd : Int = 0;
        var even : Int = 1;
        st_tv_hello.text = when (count){
            odd -> "123";
            even ->  "456";
            //if语句可以不没有else,when语句必须带上
            else ->  "789"
        }

        st_tv_hello.text = when (count){
            1,2,3,4,5,6,7,8 -> "123";
            //9~18之间
            in 9..18 ->  "456";
            //除了6~10之间
            !in 6..10 -> "222"
            //if语句可以不没有else,when语句必须带上
            else ->  "789"
        }

        //类型判断
        var iii : Int = 0;
        var countType : Number;
        countType = count.toLong();
        if(iii is Int){}else{ }
        st_tv_hello.text = when (countType){
            is Long -> "yyy";
            is Double -> "";
            else -> "";
        }
        //遍历循环 已了解
        //条件循环
        //包括1，不包括6
        for (i in 1 until 6){}
        //递增改为4
        for (i in 1..6 step 4){}
        //递减
        for (i in 50 downTo 0 ){}

        //跳出多重循环
        var e:Int =0;
        var e1:String? ="hsdgfhjklsdfkjjkl";
        outside@ while (e< e1?.length ?:0){
            var q:Int =0;
            var item : Char = e1?.get(e) ?:'e';
            while (q<item.toInt()) {
                    if(q==8){
                        break@outside
                    }
                q++
            }
            e++
        }
        //校验字符串
        //●isNullOrEmpty:为空指针或者字串长度为0时返回true,非空串与可空串均可调用。
        //●isNullOrBlank: 为空指针、字串长度为0或者全为空格时返回true,非空串与可空串均可调用
        //●isEmpty: 字串长度为0时返回true,只有非空串可调用。
        //●isBlank:字串长度为0或者全为空格时返回true，只有非空串可调用。
        //●isNotEmpty: 字串长度大于0时返回true，只有非空串可调用。
        //●isNotBlank:字串长度大于0且不是全空格串时返回true,只有非空串可调用。

        //声明可空变量
        // kotlin 空安全，所以默认(不为空)

        //非空串
        var strNotNull : String = "非空";
        //可空串
        var strCanNull : String? = null ;
        var strCanNullNew : String? = "可空串" ;

        var length  = 0;
        length = if(strCanNull!=null) strCanNull.length else -1;
        length = strCanNullNew?.length?:-1;
        //!!强行执行 将他从可空转为非空 得自己排雷
        length = strCanNullNew!!.length;
        //equals用==代替
        //is !is “变量名称!is类型名称”
        //in !in 通过“变量名!in数组名”即可判断数组是否不存在等值元素
    }
}